//
//  YSGNurseAppointmentInfoModel.swift
//  EyeVisionForPatients
//
//  Created by liuyutian on 2022/3/3.
//  Copyright © 2022 QDSG. All rights reserved.
//

import UIKit
import HandyJSON
enum YSGNurseAppointmentInfoType {
    case selectType
    case inputType
    case timeType
}
enum YSGNurseAppointmentInfoStyle {
    case singelStyle
    case firstStyle
    case lastStyle
    case tipStyle
    case normolStyle
}

class YSGNurseAppointmentInfoViewModel: NSObject {

    var dataSource : Dictionary<String,Any> = Dictionary()
    var model: YSGNurseAppointmentInfoModel?
    var familyModelArray :Array<FamilyModel> = Array()
    var mapModel : AMapTip?
    var firstSectionArray :Array<YSGNurseAppointmentInfoModel> = [
        YSGNurseAppointmentInfoModel.init(with: .inputType, _code: "adress", _style: .lastStyle, _selectArray: [], _placeHolder: "填写详细地址，例如7号楼301室", _value: "", _title: "详细地址"),
        YSGNurseAppointmentInfoModel.init(with: .selectType, _code: "patientId", _style: .tipStyle, _selectArray: [], _placeHolder: "", _value: "", _title: "选择就诊人"),
        YSGNurseAppointmentInfoModel.init(with: .selectType, _code: "medicalCardId", _style: .singelStyle, _selectArray: [["name":"医保卡","code":1],["name":"自费卡","code":2]], _placeHolder: "", _value: "", _title: "支付类型"),
        YSGNurseAppointmentInfoModel.init(with: .inputType, _code: "phone", _style: .firstStyle, _selectArray: [], _placeHolder: "填写上门联系人的联系方式", _value: "", _title: "联系方式"),

    ]
    
    var secondSectionArray :Array<YSGNurseAppointmentInfoModel>  = [
        YSGNurseAppointmentInfoModel.init(with: .timeType, _code: "appointmentTime", _style: .singelStyle, _selectArray: [], _placeHolder: "", _value: "", _title: "选择时间")
    ]
    
    var thirdSectionArray  :Array<YSGNurseAppointmentInfoModel> = [
        YSGNurseAppointmentInfoModel.init(with: .selectType, _code: "isEyeRed", _style: .firstStyle, _selectArray:[["name":"是","code":1],["name":"否","code":0]], _placeHolder: "", _value: "", _title: "眼睛是否红、肿、痛"),
        YSGNurseAppointmentInfoModel.init(with: .selectType, _code: "isSecretion", _style: .normolStyle, _selectArray: [["name":"有分泌物","code":1],["name":"无分泌物","code":0]], _placeHolder: "", _value: "", _title: "有无分泌物"),
        YSGNurseAppointmentInfoModel.init(with: .selectType, _code: "isTrichiasis", _style: .normolStyle, _selectArray:[["name":"有倒睫","code":1],["name":"无倒睫","code":0]], _placeHolder: "", _value: "", _title: "睫毛有无倒睫"),
        YSGNurseAppointmentInfoModel.init(with: .selectType, _code: "isUnobstructed", _style: .normolStyle, _selectArray: [["name":"通畅","code":1],["name":"不通畅","code":0]], _placeHolder: "", _value: "", _title: "泪道是否通畅"),
        YSGNurseAppointmentInfoModel.init(with: .selectType, _code: "isSuture", _style: .normolStyle, _selectArray: [["name":"有","code":1],["name":"无","code":0]], _placeHolder: "", _value: "", _title: "眼部是否有缝线"),
        YSGNurseAppointmentInfoModel.init(with: .inputType, _code: "suturePosition", _style: .normolStyle, _selectArray: [], _placeHolder: "输入文字", _value: "", _title: "缝线位置"),
        YSGNurseAppointmentInfoModel.init(with: .selectType, _code: "isRemove", _style: .lastStyle, _selectArray: [["name":"是","code":1],["name":"否","code":0]], _placeHolder: "", _value: "", _title: "是否需要拆线")
        
    ]
    

    override init(){
        super.init()
        
    }
    
    func sectionData(_secion : Int)-> Array<YSGNurseAppointmentInfoModel>{
        switch _secion{
        case 0 :
            return firstSectionArray
        case 1:
            return secondSectionArray
        case 2:
            return thirdSectionArray
        default :
            return []
        }
    }
    
    func sectionCount()-> (Int){
        return 3
    }
    
    func sectionRowCount(_secion : Int)-> (Int)
    {
        switch _secion{
        case 0 :
            return firstSectionArray.count
        case 1:
            return secondSectionArray.count
        case 2:
            return thirdSectionArray.count
        default:
            return 0
        }
    }
    
    
    
    
    func sectionTitleName(_secion : Int)-> String{
        switch _secion{
        case 0 :
            return ""
        case 1:
            return "选择服务时间"
        case 2:
            return "服务申请信息"
        default:
            return ""
        }
        
    }
    
    func rowHeight(_style : YSGNurseAppointmentInfoStyle) -> CGFloat
    {
        switch _style {
        case .singelStyle:
            return 51.00
        case .firstStyle:
            return 41.00
        case .lastStyle:
            return 51.00
        case .tipStyle:
            return 71.00
        case .normolStyle:
            return 41.00
        }
    }
    
    func loadFamilyMemberList(finished: @escaping (_ models: [FamilyModel]) -> Void){
        FamilyViewModel.getFamilyList(success: {[weak self] models in
            self?.familyModelArray = models
            finished(models)
        }) { errorMsg in

        }
    }
    
    
    func appointment_projectList_add(finished: @escaping (_ model:YSGNurseAppointmentAddModel?, _ errorMsg: String?, _ code: HttpCode) -> Void){
        
        HttpTool.shared.request(target: ApiManager.appointment_projectList_add(paras: dataSource), success: { (json, code) in
            if let model = JSONDeserializer<YSGNurseAppointmentAddModel>.deserializeFrom(json: json["data"].description){
                finished(model,nil, .success)
            }else{
                finished(nil, json["message"].description, .failure)
            }
        }) { errorMsg in
            finished(nil, errorMsg, .failure)
        }
    }
    
}

struct YSGNurseAppointmentAddModel: HandyJSON{
    var appointmentId :String?
    var orderId :String?
    var orderNumber :String?
}

class YSGNurseAppointmentInfoModel: NSObject {
    
    var type : YSGNurseAppointmentInfoType?
    var code : String = ""
    var style : YSGNurseAppointmentInfoStyle?
    var selectArray : Array<NSDictionary>?
    var placeHolder : String?
    var value : String = ""
    var title : String?
    
    
    init(with _type : YSGNurseAppointmentInfoType,
         _code : String,
         _style : YSGNurseAppointmentInfoStyle,
         _selectArray : Array<NSDictionary>,
         _placeHolder : String,
         _value : String,
         _title : String) {
        super.init()
        type = _type
        code = _code
        style = _style
        selectArray = _selectArray
        placeHolder = _placeHolder
        value = _value
        title = _title
    }
}



